
var SortJson = [];
var app_url=location.origin;
var EDITMODE=false; 
//日期格式化
var calendarDateFormat = myApp.calendar({
	input: '#start_time',
    monthNames: ['01'+_(''+_('月')), '02'+_('月'), '03'+_('月'), '04'+_('月'), '05'+_('月'), '06'+_('月'), '07'+_('月'), '08'+_('月') , '09'+_('月') , '10'+_('月'), '11'+_('月'), '12'+_('月')],
    dayNamesShort: [_('日'), _('一'), _('二'), _('三'), _('四'), _('五'), _('六')],
    closeOnSelect:true,
});
var calendarDateFormat = myApp.calendar({
	input: '#end_time',
    monthNames: ['01'+_(''+_('月')), '02'+_('月'), '03'+_('月'), '04'+_('月'), '05'+_('月'), '06'+_('月'), '07'+_('月'), '08'+_('月') , '09'+_('月') , '10'+_('月'), '11'+_('月'), '12'+_('月')],
    dayNamesShort: [_('日'), _('一'), _('二'), _('三'), _('四'), _('五'), _('六')],
    closeOnSelect:true,
});
(function(){
	var apply = {
		init: function(){
			this.PayLoad();
			this.bindEvents();
			this.SalesLoad();
		},
		bindEvents:function(){
			var self = this;
			 //跳转页面
             $("#navMenu a").on("click",function(){
            	var link_url=$(this).attr("data-href");
            	if(APP){
            		var appJson={};
           			appJson.title=$(this).attr("data-title");
           			appJson.url=app_url+link_url;	
           			YiYi_APP.showNewPage(JSON.stringify(appJson));
            	}else{
            		location.href = link_url;
            	}
            });
			
			//点击筛选按钮
			$("#show_term_btn").on("click", function () {
				myApp.popup(".user_filter_box");
			});
			//确定筛选
			$("#confirm_btn").on("click",function(){
				self.PayLoad();//获取数据列表
				myApp.closeModal(".user_filter_box");
			});
			//重置
			$("input[type=reset]").on("click",function(){
				$("#_role li").removeClass("add_blue").css("background","#a1a1a1");
			});
			//排序方式
            $("#product_table_fixed th").on("click", function () {
				sortFun($(this));
            });
			
		},
		//获取参数
        getParamer:function(){
            var requestApplys = {};

            if(RoleID == 1 || RoleID == 2){                
                requestApplys.UserRealName= $.trim($("#_saleRealName").val());
            }else{
                requestApplys.ApplyID = UserID;
            }

            //名字cookie 充值页面传来的_rnick  10-28
            if($.cookie("_rnick")){
                $("#_customerRealName").val($.cookie("_rnick"));//真名
                $.cookie("_rnick","",-1);
            }

            requestApplys.CustomerNickName = $.trim($("#_customerCs").val());//昵称
            requestApplys.CustomerRealName = $.trim($("#_customerRealName").val());

            requestApplys.Amount = $("#_amt").val();//12-21

            if( $.cookie("_charge_statu_c")){
                requestApplys.Status=0;//待审核
                $("._charge_statu_c").addClass("current").siblings().removeClass("current");
                $.cookie("_charge_statu_c","",-1);
            }
            requestApplys.Status = $("#_sysStatus>ul li.add_blue").attr("data-value");//下拉框

            requestApplys.Account = $("#sel_accountID").val();
            requestApplys.Type = $("#sel_type").val();
            requestApplys.Abstract = $("#sel_abstract").val();//摘要
            requestApplys.Currency = $("#sel_currency").val();//币种
            requestApplys.SCreateTime = $("#screatetime").val();
            requestApplys.ECreateTime = $("#ecreatetime").val();
            requestApplys.SUpdateTime = $("#supdatetime").val();
            requestApplys.EUpdateTime = $("#eupdatetime").val();
            requestApplys.PageSize = 500; //id=_pageSizes
            requestApplys.PageIndex = 1;//.page_num是class
            return requestApplys;
        },
        //获取参数
        getParamer:function() {
           var requestOrder = {};
           requestOrder.CustomerNickName = $.trim($("#_customerNickName").val());
            //requestOrder.CustomerRealName = $("#_customerRealName").val();
           requestOrder.SN =$.trim($("#_sN").val());

            //业务员3
           if(RoleID != 1){
                requestOrder.SalesUserID = UserID;
            }else{
                requestOrder.SalesUserID = $("#_salesUserID option:checked").val();
            }
            requestOrder.SCreateTime = $("#start_time").val();//start_time 起始支付时间
            requestOrder.ECreateTime = $("#end_time").val();//end_time 结束支付时间          
            requestOrder.PageSize = 500; //id=_pageSizes //单页数量
            requestOrder.PageIndex = 1;//.page_num是class //页码

            return requestOrder;
        },
        //加载(公用)
         PayLoad:function(p) {
         	var self = this;
            myApp.showIndicator();
            if (p) {
                var requestOrder = p;
            } else {
                var requestOrder =self.getParamer(requestOrder);
            }
            $.ajax({
                url: "/Team/GetPays",//提交地址
                type: "POST",//提交方式
                data: JSON.stringify(requestOrder),
                contentType: "application/json; charset=utf-8",
                success: function (result) {
                	
                	var _result = eval('(' + result + ')');//eval()解析单个json对象

		            if (_result.msgcode == false) {
		            	
		                var tr = "";//单行
		                var tds = "<td colspan='9' style='text-align:center;color:red'>" + _(_result.msginfo) + "</td>";// 多列合成一列并居中
		                tr = "<tr>" + tds + "</tr>";//将多列加到一行
		                $("#stock_body").html(tr);//加入到id为customer的table的tbody中
		            } else {
		            	_result = _result.msginfo.Data;//object
			            SortJson = _result;
		            	BindingData(_result, $("#stock_body"));//绑定数据
		            }
                    
                   	myApp.hideIndicator(); 
                   
                }
            });
        },
                //业务列表
         SalesLoad:function(){            
            $.ajax({
                url: "/Team/GetSaleList",//提交地址
                type: "POST",//提交方式
                data: "{'PageSize':'" + 100 + "','PageIndex':'" + 1 + "'}",
                contentType: "application/json; charset=utf-8",
                success: function (result) {
                    var _result = eval('(' + result + ')');//eval()解析单个json对象
                
                    if(_result.msgcode == false){

                        var options_sales = "";
                        options_sales += '<option value="">' + _(_result.msginfo) + '</option>';
                        $("#_salesUserID").html("");
                        $("#_salesUserID").html(options_sales);    
                        
                    }else{

                        var options_sales = "";
                        options_sales += '<option value="">'+_("业务")+'</option>';
                        for (var i = 0; i < _result.length; i++) {
                            options_sales += '<option value="' + _result[i].UserID + '"  >' + _result[i].RealName + '</option>';
                        }
                        $("#_salesUserID").html("");
                        $("#_salesUserID").html(options_sales); 
                    }
                }
            });
        },
	}
	apply.init();
})();
   			//绑定数据
			function BindingData(_result, tableTbody) {
                var trs = "";//多行数据

                for (var i = 0; i < _result.length; i++) {

                    var tds = "";//多列
                    var tr = "";//单行
                    tds += "<td>" + (i+1) + "</td>";
                    tds += "<td>" + SNFormat(_result[i].SN) + "</td>";                   
                    tds += "<td>" + _result[i].CustomerNickName + "</td>";
//                  tds += "<td>" + _result[i].CustomerRealName + "</td>";
                    tds += "<td>" + _result[i].SalesUserName + "</td>";
                    tds += "<td>" + CurrencyFormat(_result[i].CurType) + "</td>";
                    if(_result[i].CurType == 1){
                        tds += "<td>" + ConfirmPriceFormat(Math.round(_result[i].ConfirmPrice)) + "</td>";
                    }else if(_result[i].CurType == 2){
                        tds += "<td>" + Math.round(_result[i].ConfirmUSD) + "</td>";
                    }
                    tds += "<td>" + DateTimeFormat(_result[i].PayTime) + "</td>";
                    tds += "<td>" + PaymentStatusFormat(_result[i].PaymentStatus) + "</td>";
                    tr += "<tr>" + tds + "</tr>";//将多列加到一行

                    trs += tr;//将单行加到多行
                }  
                    
                
                $("#stock_body").html(trs);//加入到id为customer的table的tbody中
            }
